const request = getApp().globalData.request;
const HOST = getApp().globalData.HOST;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		content: true,
		order: []
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		this.getOrder();
	},
	getOrder() {
		let that = this;
		request.get(HOST + "wxphp/order.php", {
			pagesize: 30,
			page: 0
		}).then((res) => {
			if (res.data.length != 0) {
				that.setData({
					content: false
				})
			}
			// console.log(res)
			that.setData({
				order: res.data
			})
		})
	},
	//删除
	Delete(e) {
		let that = this;
		let id = e.currentTarget.dataset.index;
		wx.showModal({
			title: "提示",
			content: "确定撤回这条记录吗",
			success: function(res) {
				if (res.confirm) {
					console.log("确定");
					request.get(HOST + "wxphp/order.php", {
						type: "delete",
						id: id
					}).then((res) => {
						if (!res.data.state) { //判断成功
							wx.showToast({
								title: "撤回失败",
								icon: 'none',
								duration: 1000
							})
						} else {
							wx.showToast({
								title: "撤回成功",
								icon: 'none',
								duration: 1000
							})
							that.getOrder();
						}
					})
				} else {

					console.log("取消")
				}
			}
		})
		
	},
	cx() {
		wx.showToast({
			title: '不可操作',
			icon: 'none',
			duration: 1000
		})
	},


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
